package elearning.record.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import elearning.record.entity.Note;

public class NoteDao extends HibernateDaoSupport{

	public List<Note> findNoteByCourseId(Integer courseid) {
		String hql = "from Note where videoId in(select videoId from Video where courseId = ?)";
		@SuppressWarnings("unchecked")
		List<Note> list = this.getHibernateTemplate().find(hql,courseid);
		if(list.size()>0&&list!=null){
			return list;
		}
		return null;
	}

	public List<Note> findNoteByUid(Integer uid) {
		String hql = "from Note where userId = ?";
		@SuppressWarnings("unchecked")
		List<Note> list = this.getHibernateTemplate().find(hql,uid);
		if(list.size()>0&&list!=null){
			return list;
		}
		return null;
	}

	public void findByNoteId(Integer noteId) {
	
		Note note = this.getHibernateTemplate().get(Note.class,noteId);
		note.setNoteFor(note.getNoteFor()+1);
		this.getHibernateTemplate().update(note);
	}

	public void save(Note note) {
		this.getHibernateTemplate().save(note);
	}

}
